const express = require("express");
const db = require("./db/db_link");
const rejister_logion = require("./router/rejister_login")
const app = express();
const cors = require("cors");
const student_info = require("./router/student");
const inquire_info = require("./router/inquire_info")
const update_info = require("./router/update_info")
const delete_info = require("./router/delete_info")
app.use(cors())
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({
    extended: true
}))
app.use(student_info)
app.use(rejister_logion)
app.use(inquire_info)
app.use(update_info)
app.use(delete_info)
//链接数据库全局中中间件
app.use("/", async (req, res, next) => {
    try {
        await db;
        next();
    } catch (err) {
        console.log(err)
        res.send("服务器和数据库连接失败");
    }
})

app.listen(3000, (err) => {
    if (!err) {
        console.log("服务器启动成功")
    } else {
        console.log(err)
    }
})